package com.kerry.test.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.kerry.test.model.Product;
import com.kerry.test.repository.ProductRepository;

@Controller
public class ProductSearchController<solrProductRepository> {
	
	@Autowired
	private ProductRepository productRepository;
	
	
	@RequestMapping("/product/search")
	public String search(){
		
//		Product initial = createProduct(1);
//		productRepository.save(initial);
//
		Product loaded = productRepository.findOne("1");
		
		System.out.println(loaded.toString());
		
		System.out.println("66666666666666666");
		
		return "/index";
	}
	
	
	 protected List<Product> createProductList(int nrProducts) {
		    List<Product> products = new ArrayList<Product>(nrProducts);
		    for (int i = 0; i < nrProducts; i++) {
		      products.add(createProduct(i));
		    }
		    return products;
		  }

		  protected Product createProduct(int id) {
		    Product product = new Product();
		    product.setId(Integer.toString(id));
		    product.setAvailable(id % 2 == 0);
		    product.setName("product-" + id);
		    product.setPopularity(id * 10);
		    product.setPrice((float) id * 100);
		    product.setWeight((float) id * 2);
		    return product;
		  }

}
